﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sysgeprava.Entities;
using Sysgeprava.Repository;
using Microsoft.Practices.Unity;

namespace Sysgeprava.BL
{
    public class BovinoBL:IBovinoBL
    {
        //hola mundo
        [Dependency]
        public IBovinoRepository bovinoDAO { get; set; }

        public List<BOVINO> GetAllFromBovino()
        {
            return bovinoDAO.GetAllFromBovino();
        }

        public List<BOVINO> GetAllFromBovinoByCriterio(string criterio)
        {
            return bovinoDAO.GetAllFromBovinoByCriterio(criterio);
        }

        public BOVINO GetAllFromBovinoById(int id)
        {
            return bovinoDAO.GetAllFromBovinoById(id);
        }

        public BOVINO GetAllFromBovinoByArete(string arete)
        {
            return bovinoDAO.GetAllFromBovinoByArete(arete);
        }

        public void AddBovino(BOVINO bovino)
        {
            var msg = "";
            var ok = bovino.Validate(out msg);
            if (ok)
            {
                bovinoDAO.AddBovino(bovino);
            }
            else
            {
                throw new Exception(msg);
            }
        }

        public void UpdateBovino(BOVINO bovino)
        {
            var msg = "";
            var ok = bovino.Validate(out msg);
            if (ok)
            {
                bovinoDAO.UpdateBovino(bovino);
            }
            else
            {
                throw new Exception(msg);
            }
        }
    }
}
